/**
 * User: Anton Petrov
 * Date: 3/10/13
 * Time: 7:03 PM
 */
package com.antonpetrov.controller.factory
{
	import com.antonpetrov.model.word.BasicWord;

	public class WordsFactory
	{
		/**
		 * Given an array of strings, it creates words by taking every two
		 * consecutive elements in the array as one word - the first element
		 * is the word itself and the second - the explanation of that word.
		 * @param input An Array of strings representing basic words.
		 * @return An Array of Basic Words created from the input strings.
		 */
		public static function createWordsFromArrayOfStrings(input:Array):Array
		{
			if (input == null || (input.length % 2 != 0))
			{
				throw new Error(
					"Invalid input array of strings to create words from.");
			}

			var result:Array = [];
			for (var i:int = 0; i < input.length - 1; i += 2)
			{
				var word:String = String(input[i]);
				var explanation:String = String(input[i + 1]);

				result.push(new BasicWord(word,  explanation));
			}

			return result;
		}
	}
}
